# Contributor: Steve McMaster <code@mcmaster.io>
# Contributor: Karim Kanso <kaz.kanso@gmail.com>
# Contributor: Michael Mason <ms13sp@gmail.com>
# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=snort
# pair with snort-extra
pkgver=3.1.82.0
pkgrel=0
pkgdesc="Open source network intrusion prevention and detection system"
url="https://www.snort.org/"
# luajit
arch="all !ppc64le !riscv64 !loongarch64"
license="GPL-2.0-only"
depends="bash"
makedepends="
	bison
	cmake
	daq-dev
	daq-static
	flex-dev
	hwloc-dev
	libdnet-dev
	libmnl-dev
	libnet-dev
	libnetfilter_queue-dev
	libnfnetlink-dev
	libpcap-dev
	libtirpc-dev
	luajit-dev
	openssl-dev
	pcre-dev
	samurai
	xz-dev
	zlib-dev
	"
install="$pkgname.pre-install"
pkgusers="snort"
pkggroups="snort"
subpackages="$pkgname-doc $pkgname-dev $pkgname-openrc"
source="https://www.snort.org/downloads/snortplus/snort3-$pkgver.tar.gz
	gcc13.patch
	no-libunwind.patch
	logrotate
	snort.initd
	snort.confd
	"
builddir="$srcdir/snort3-$pkgver"
options="!check" # needs cpputest from community

# secfixes:
#   2.9.18-r0:
#     - CVE-2021-40114

build() {
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DENABLE_UNIT_TESTS="$(want_check && echo ON || echo OFF)" \
		-DENABLE_BENCHMARK_TESTS=OFF
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm 755 "$srcdir"/snort.initd "$pkgdir"/etc/init.d/snort
	install -Dm 644 "$srcdir"/snort.confd "$pkgdir"/etc/conf.d/snort
	install -Dm644 "$srcdir"/logrotate "$pkgdir"/etc/logrotate.d/snort
	install -d -o snort -g snort -m 770 "$pkgdir"/var/log/snort "$pkgdir"/var/lib/snort
}

sha512sums="
b7ed9e67946d857a9545e3a4616de11668d4f9f64d1d3b58d9c7218b105f8b7d6b2ce195239a1506d5a86fe80faa097860e35216d686bd3e5e495dd659d0324e  snort3-3.1.82.0.tar.gz
741c1d30a19f18ec33c9f10a696e510d5edc35969e12121920c2a05e6de18d3d74bda42ef7e9d01f60124c08b1e8f3f47e06b6baaa52f4fb7f6834a0d1ad77e6  gcc13.patch
9fdf8bdf17fa84326fc1f04ee3bf0d14ce4df60c62f7ed3e6303644ae674316f6d6e4c5318791a01921a9bb64dd0de2304688eb98243e0f313ed3f2d93e1d33e  no-libunwind.patch
2d845baa9cd02237a6e60dc280ede896bf1facf7906d7d08e8dfa99d596a9fbe3de4227e6bedbd95375598b6940b9d874ccdd12d3f2c1ede282bac3a8e26b47e  logrotate
769840c6e8a7e353a2b2866b7b161195ce780fb3d5dda747325a95fcaf964c9aad29c5aba8c8ea48aa26ef810d81e82c1321104dd3e7374319e8176635e9b7d8  snort.initd
8a1139cdd07a03a96c7f5f75164bf95cae4dbc24f637d8b4008b0cf41e4a7f97148621fe4a1c867e956e16dbe226eaf2284a50b73547d1afaacbd32ca9befae5  snort.confd
"
